function front_blog_card(
  post_url = '#',
  icon_url = '#',
  title = '暂无标题',
  username = '匿名用户',
  datetime = '暂无时间',
  like = 0,
  sort = '暂无类别'
) {
  const htmlString = `
    <div class="card mb-4" style="cursor: pointer;" onclick="window.location.href='${post_url}'">
      <div class="card-body">
        <h5 class="card-title">${title}</h5>
      </div>
      <hr class="my-2">
      <div class="d-flex align-items-center px-3 pb-3">
        <img src="${icon_url}" alt="用户头像" class="rounded-circle me-2" style="width: 30px; height: 30px; object-fit: cover;">
         &nbsp;${username} &nbsp;
        <span class="me-3 text-muted">
          <i class="bi bi-calendar-event"></i> ${datetime}
        </span>
        <span class="text-danger">
          <i class="bi bi-heart-fill"></i> ${like}
        </span>
        <span class="badge bg-primary text-light ms-2">${sort}</span>
      </div>
    </div>
  `;
  return htmlString;
}

function table_item(...components) {
    const tds = components.map(item => `<td>${item}</td>`).join('');
    return `<tr>${tds}</tr>`;
}


function front_blog_table_item(
  post_url = '#',
  title = '暂无标题',
  sort = '暂无类别',  // 新增sort参数
  datetime = '暂无时间',
  reason=null,
  edit_url = null,
  delete_url = null
){
  let htmlString = `
    <tr>
      <td><a href="${post_url}">${title}</a></td>
      <td>${sort}</td>  <!-- 分类列 -->
      <td>${datetime}</td>  <!-- 日期列 -->
  `;

  if(reason){
    htmlString+=`<td>${reason}</td>`;
  }

  if(edit_url){
    htmlString += `<td><a href="${edit_url}" class="btn btn-sm btn-primary">修改</a></td>`;
  }

  if(delete_url){
    htmlString += `<td><a href="${delete_url}" class="btn btn-sm btn-primary">删除</a></td>`;
  }

  htmlString += `</tr>`;
  return htmlString;
}

function front_comment_table_item(
  post_url = '#',
  pid=0,
  content = '暂无内容',
  datetime = '暂无时间',
  delete_url = null
) {
  let htmlString = `
    <tr>
      <td><a href="${post_url}">${pid}</a></td>
      <td>${content}</td>
      <td>${datetime}</td>  <!-- 日期列 -->
  `;

  if (delete_url) {
    htmlString += `<td><a href="${delete_url}" class="btn btn-sm btn-danger">删除</a></td>`;
  }

  htmlString += `</tr>`;
  return htmlString;
}
